package 数组;

public class SolutionDemo02 {
    public int removeElement(int[] nums, int val) {
        int i = 0;
        int j = 0;
        int len = nums.length;
        while (i <= len - 1 && j <= len - 1) {
            if (nums[i] == val) {
                j = i + 1;
                while (j <= len - 1 && nums[j] == val) {
                    j++;
                }
                if (j > len - 1) {
                    break;
                }
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
            i++;
        }
        return i;
    }
}
